<?php

if (!defined("EXPONENT")) exit("");
	$album = null;		
	if (isset($_POST['id'])) {
		$album = $db->selectObject('album', 'id='.$_POST['id']);
		if ($album != null) {
			$loc = unserialize($album->location_data);
		} 
	} else {
		$album->rank = $db->max('album', 'rank', null, "location_data='".serialize($loc)."'");
		if ($album->rank == null) {
			$album->rank = 0;
		} else { 
			$album->rank += 1;
		}
	}
	
	if (exponent_permissions_check("manage",$loc)) {	
			$config = $db->selectObject('albummodule_config',"location_data='".serialize($loc)."'");
		  if (!$config) {
			//do nothing here yes.
			   $config->album_type=0; // 0 for christian
      }
		
		$album= album::update($_POST, $album);
		$album->location_data = serialize($loc);
		$album->album_type = $config->album_type;
		if (isset($album->id)) {
			// calculate all song length
      $db->updateObject($album,"album");
		} else {
			$db->insertObject($album,"album");
		}		
		
		exponent_flow_redirect();
	} else {
		echo SITE_403_HTML;
	}
	

?>
